home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / elm / elm2.4 / lib / gcos_name.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-19  |  2.4 KB  |  98 lines

  1. static char rcsid[] = "@(#)$Id: gcos_name.c,v 5.2 1993/01/20 03:02:19 syd Exp $";
  2.  
  3. /*******************************************************************************
  4.  *  The Elm Mail System  -  $Revision: 5.2 $   $State: Exp $
  5.  *
  6.  *            Copyright (c) 1988-1992 USENET Community Trust
  7.  *            Copyright (c) 1986,1987 Dave Taylor
  8.  *******************************************************************************
  9.  * Bug reports, patches, comments, suggestions should be sent to:
  10.  *
  11.  *    Syd Weinstein, Elm Coordinator
  12.  *    elm@DSI.COM            dsinc!elm
  13.  *
  14.  *******************************************************************************
  15.  * $Log: gcos_name.c,v $
  16.  * Revision 5.2  1993/01/20  03:02:19  syd
  17.  * Move string declarations to defs.h
  18.  * From: Syd
  19.  *
  20.  * Revision 5.1  1992/10/03  22:41:36  syd
  21.  * Initial checkin as of 2.4 Release at PL0
  22.  *
  23.  *
  24.  ******************************************************************************/
  25.  
  26. /** 
  27.  
  28. **/
  29.  
  30. #include "headers.h"
  31. #include <ctype.h>
  32.  
  33. #ifdef BSD 
  34. #undef tolower
  35. #undef toupper
  36. #endif
  37.  
  38. char *
  39. gcos_name(gcos_field, logname)
  40. char *logname, *gcos_field;
  41. {
  42.     /** Return the full name found in a passwd file gcos field **/
  43.  
  44. #ifdef BERKNAMES
  45.  
  46.     static char fullname[SLEN];
  47.     register char *fncp, *gcoscp, *lncp, *end;
  48.  
  49.  
  50.     /* full name is all chars up to first ',' (or whole gcos, if no ',') */
  51.     /* replace any & with logname in upper case */
  52.  
  53.     for(fncp = fullname, gcoscp= gcos_field, end = fullname + SLEN - 1;
  54.         (*gcoscp != ',' && *gcoscp != '\0' && fncp != end);
  55.     gcoscp++) {
  56.  
  57.     if(*gcoscp == '&') {
  58.         for(lncp = logname; *lncp; fncp++, lncp++)
  59.         *fncp = toupper(*lncp);
  60.     } else {
  61.         *fncp++ = *gcoscp;
  62.     }
  63.     }
  64.     
  65.     *fncp = '\0';
  66.     return(fullname);
  67. #else
  68. #ifdef USGNAMES
  69.  
  70.     char *firstcp, *lastcp;
  71.  
  72.     /* The last character of the full name is the one preceding the first
  73.      * '('. If there is no '(', then the full name ends at the end of the
  74.      * gcos field.
  75.      */
  76.     if(lastcp = index(gcos_field, '('))
  77.     *lastcp = '\0';
  78.  
  79.     /* The first character of the full name is the one following the 
  80.      * last '-' before that ending character. NOTE: that's why we
  81.      * establish the ending character first!
  82.      * If there is no '-' before the ending character, then the fullname
  83.      * begins at the beginning of the gcos field.
  84.      */
  85.     if(firstcp = rindex(gcos_field, '-'))
  86.     firstcp++;
  87.     else
  88.     firstcp = gcos_field;
  89.  
  90.     return(firstcp);
  91.  
  92. #else
  93.     /* use full gcos field */
  94.     return(gcos_field);
  95. #endif
  96. #endif
  97. }
  98.